<script type="text/javascript">
	$(document).ready(function(){
		$('#sortable_answers_<?php echo $question['Question']['id'];?>').sortable({

		   stop: function(event, ui) {		   	
				var answer_order_array = $( "#sortable_answers_<?php echo $question['Question']['id'];?>" ).sortable("toArray");
				$.post("/answers/reorder/", { 'data[answers]': [answer_order_array] });
		   }

		});
	});
</script>
<?php
	$assessment_breadcrum = $ajax->link(
		'Assessment',
		array( 'controller' => 'questiongroups', 'action' => 'ajax_get', $assessment['Assessment']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading')
	);
	$questiongroup_breadcrum = $ajax->link(
		'Question Group',
		array( 'controller' => 'questiongroups', 'action' => 'ajax_edit', $questiongroup['Questiongroup']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading')
	);
	
	$question_breadcrum = $ajax->link(
		'Questions',
		array( 'controller' => 'questions', 'action' => 'ajax_get', $questiongroup['Questiongroup']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading')
	);
	
	$questionedit_breadcrum = $ajax->link(
		'Question',
		array( 'controller' => 'questions', 'action' => 'ajax_edit', $question['Question']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading')
	);

?>
<div id="whiteBG">
<div id="crumb"><ul>
	<li class="crumbMiddle" id="crumb01"><?php echo $assessment_breadcrum;?></li>
	<li class="crumbMiddle" id="crumb02"><?php echo $questiongroup_breadcrum;?></li>
	<li class="crumbMiddle" id="crumb03"><?php echo $question_breadcrum;?></li>
	<li class="crumbMiddle" id="crumb04mid"><?php echo $questionedit_breadcrum;?></li>
	<li class="crumbMiddle" id="crumb05on"><a href="#">Answers</a></li>
	<li class="crumbMiddle" id="crumb06">Answer</li>
</ul></div> 
<div class="assessment">
	<div class="eTitle">
		<h2><?php echo $question['Question']['name'];?></h2>
	</div>
<div class="aTable">
	<div class="aTableHeader">
		<span class="aTableDelete">Delete</span>
		<span class="aTableDuplicate">Correct</span>
		<span class="aTableEdit">Edit</span>
		<span class="aTableAnswer">Answer</span>
	</div>
<?php
$i = 0;//switch between 1 and 0 to toggle between the two list classes
foreach ($question['Answer'] as $answer)
{

	$answer_delete_ajax = $ajax->link(
		'[x]',
		array( 'controller' => 'answers', 'action' => 'ajax_delete', $answer['id']),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'confirm' => 'Are you sure?', 'indicator' => 'loading')
	);
	$answer_delete_ajax_img = str_replace('[x]','<span class="iconDelete"></span>',  $answer_delete_ajax);

	$answer_edit_ajax = $ajax->link(
		'[x]',
		array( 'controller' => 'answers', 'action' => 'ajax_edit', $answer['id']),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading_answer_form')
	);
	$answer_edit_ajax_img = str_replace('[x]','<span class="iconEdit"></span>',  $answer_edit_ajax);				

	$print_answer = '';

	if ($question['Answervalue']['variable_type'] == 'text'){

		if (strlen($answer['answer_text']) > 40){
			$answer['answer_text'] = substr($answer['answer_text'],0,40);
			$answer['answer_text'] .= '..';
		}

		$print_answer = $answer['answer_text'];

	}
	elseif ($question['Answervalue']['variable_type'] == 'decimal'){
		$print_answer = $answer['answer_decimal'].'&nbsp;'.$question['Answervalue']['abbreviation'];
	}
	elseif ($question['Answervalue']['variable_type'] == 'int'){
		$print_answer = $answer['answer_int'].'&nbsp;'.$question['Answervalue']['abbreviation'];
	}
	elseif ($question['Answervalue']['variable_type'] == 'file'){
		$print_answer = $answer['answer_text'];
	}

	if($answer['correct'] == 1){
		$is_answer_correct = '<img src="/img/tick.png">';
	}else{	
		$is_answer_correct = '<img src="/img/cross.png">';
	}
	
	if($i == 0)
	{
		$answers .=  '<div class="aTableRowA" id="'.$answer['id'].'">';
		$i = 1;
	}
	else
	{
		$answers .=  '<div class="aTableRowB" id="'.$answer['id'].'">';
		$i = 0;
	}
	$answers .=
		'
			
			<li id="'.$answer['id'].'">
				<span class="aTableDelete">'.$answer_delete_ajax_img.'</span>
				<span class="aTableDuplicate">'.$is_answer_correct.'</span>
				<span class="aTableEdit">'.$answer_edit_ajax_img.'</span>
				<span class="aTableAnswer">'.$answer['answer_text'].'</span>
			</li>
			</div>
		';
}
echo '<ul id="sortable_answers_'.$question['Question']['id'] .'">'.
		$answers.
	 '</ul>';
	 
	 $answer_add_ajax = $ajax->link(
		'[x]',
		array( 'controller' => 'answers', 'action' => 'ajax_add', $question['Question']['id'] ),
		array( 'update' => 'edit_div_'.$assessment['Assessment']['id'], 'indicator' => 'loading_question')
	);
	$answer_add_ajax_img = str_replace('[x]','<span class="iconNew"></span><p>Add Answer</p>',  $answer_add_ajax);
	
	echo "<div class='aTableRowC'" . $answer_add_ajax_img . "</div>" // . " Add Answer";
?>
</div>